/**
 * RandomTwo.java
 * write a detailed explanation for each of the lines 5, 6 12, 15, 16, 18-30
 *
 * @author: Sun Microsystems
 *  Editor: John Thomason
 *    Date: Nov 6, 2008 / 7:22:00 AM
 *   Class: CS222 Java II
 */

/**
 * RandomTwo Class
 */
public class RandomTwo {

  /**
   * Application Entry Point
   * @param args The command line arguments
   */
  public static void main(String[] args) {
    
    /**
     * Create an instance of the ObjectTwo class, and store
     * the reference to the new object in the identifier 'two'.
     * The new object is stored on the heap, while the reference
     * is on the stack.
     */
    ObjectTwo two = new ObjectTwo();            //Line 5;
    
    /**
     * Call the 'go' method from the 'two' object.
     */
    two.go();                                   //Line 6;

  }//end main()

}//end RandomTwo class

/**
 * ObjectTwo Class
 */
class ObjectTwo {
  
  /**
   * go()
   * The method called from the main method above.
   */
  public void go(){                             //Line 12;
    
    int max = 10;
    /**
     * Generate two separate random values between 1 and max (inclusive).
     * 
     * The Math class is part of java.lang, so it does not require importing.
     * 
     * Math.random() returns a double between 0.0 and less than 1.
     * You must use parenthesis around (Math.random() * max) to modify
     * the order in-which the expression is evaluated. 
     * 
     * Casting has a higher precedence than multiplication, so the parenthesis
     * are mandatory to evaluate (Math.random() * max) before casting to an int. 
     * Otherwise, you will ALWAYS generate zero(0) as the random value
     * (I've done that once or twice!).
     * 
     * (int)(Math.random() * max) returns a random integer between zero(0)
     * and (max - 1). By adding one(1) to the result, we store a random
     * value between 1 and max (inclusive) in 'rand1' and 'rand2'.
     */
    int rand1 = (int)(Math.random() * max) + 1; //Line 15;
    int rand2 = (int)(Math.random() * max) + 1; //Line 16;

    /**
     * Evaluate the values in rand1 and rand2, then display the appropriate
     * message (Bananas, Oranges, Pears).
     * 
     * If the value of rand1 is less than or equal to three(3), then display
     * 'Bananas' regardless of the value in rand2.
     * 
     * If the value of rand1 is greater than three(3), then evaluate rand2.
     * 
     * If the value of rand1 is greater than three(3), AND the value of rand2
     * is less than or equal to five(5), then display 'Oranges'
     * 
     * If the value of rand1 is greater than three(3), AND the value of rand2
     * is greater than five(5), then display 'Pears'
     */
    if( rand1 <= 3 ){                           //Line 18;
      System.out.println("Bananas");
    }
    else {

      if( rand2 <= 5 ){
        System.out.println("Oranges");
      }
      else {
        System.out.println("Pears");
      }//if()

    }//if()                                     //Line 30;

  }//go()
  
}//End ObjectTwo class
